package com.doctor.ui;

import java.util.List;

import com.doctor.bean.ArticleVideoMaxIdBean;
import com.doctor.bean.ArticleVideoMaxIdListBean;
import com.doctor.bean.UserBean;
import com.doctor.bean.UserListBean;
import com.doctor.comm.ConstConfig;
import com.doctor.comm.DialogHelper;
import com.doctor.comm.FileHelper;
import com.doctor.comm.ImageHelper;
import com.doctor.comm.LoadingTip;
import com.doctor.comm.MyApplication;
import com.doctor.comm.URLConfig;
import com.doctor.database.DbOperator;
import com.doctor.net.GetDataThread;
import com.doctor.net.NetUtil;
import com.doctor.net.RequestParams;
import com.doctor.ui.setting.UserInfoActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class BaseFragmentActivity extends FragmentActivity{

	private ImageView photo;  //圆形头像
	protected LinearLayout officeBtn,knowledgeBtn,consultingBtn,homeDocBtn;  //主菜单项
	private Bitmap bitmap;
	protected LinearLayout fragContainer;
	//actionBar上的按钮
	protected FrameLayout menuControlBtn,searchBtn,webSiteBtn,videoBtn,articleBtn;
	//主菜单
	private View mainMenu;
	//子菜单
	protected GridView subMenu;
	//搜索字
	protected TextView searchText;
	//搜索输入框
	protected EditText search;
	//点击退出时间
	private long oldTime;
	private Handler handler;
	private static final int INITIA_VALUE=-1;
	//1医学栏目，2健康管理、3医学知识库、4视频、5验证用户是否在有效期内
	private static final int MSG_DIR=1,MSG_HEALTH=2,MSG_ARTICLE=3,MSG_VIDEO=4,MSG_VERIFY=5;
	//栏目、健康管理、知识库或视频的升级数量
	private int dirCount=INITIA_VALUE,healthCount=INITIA_VALUE,articleOrVideoCount=INITIA_VALUE;
	//判断点击的是哪个升级，1知识库，2视频
	private int updateWhich;
	//栏目、健康管理、知识库、视频是否完成
	private boolean dirDone,healthDone,articleDone,videoDone;
	//显示医学知识库、视频累计升级数量
	private TextView knowledgeCountTip,videoCountTip;
	//是否去过网站(升级前得先去下网站这个奇葩规定)
	private boolean hasGotoWebSite;
	//记录升级数据数量
	public static final int MSG_UPFATE_COUNT = -10;
	//输入升级密码对话框
	private Dialog dialog;
	
	
	//竖屏时隐藏左边菜单
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		// TODO Auto-generated method stub
		super.onConfigurationChanged(newConfig);
		if (newConfig.orientation==ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
			mainMenu.setVisibility(View.VISIBLE);
		} else if (newConfig.orientation==ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
			//竖屏隐藏左侧菜单
			mainMenu.setVisibility(View.GONE);
		}
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (getSupportFragmentManager().getBackStackEntryCount()<=0) {
				long nowTime= java.lang.System.currentTimeMillis();
				long between = nowTime- oldTime;
				if (between<=2000) {
					DbOperator.getInstance(BaseFragmentActivity.this).close();
					MyApplication.getInstance().setHasNoticeNewData(false);
					BaseFragmentActivity.this.finish();
					java.lang.System.exit(0);
				}else {
					oldTime= nowTime;
					Toast.makeText(BaseFragmentActivity.this, "再按一次退出医师宝！", 2000).show();
				}
				return true;
			}
			return super.onKeyDown(keyCode, event);
		}
		return false;
	}
	
	protected void initiaView(){
		if (bitmap!=null && !bitmap.isRecycled()) {
			bitmap.recycle();
			bitmap=null;
		}
		System.gc();
		
		search=(EditText) findViewById(R.id.search_word_editext);
		
		mainMenu=findViewById(R.id.main_menu);
		
		MainMenuClickListener clickListener=new MainMenuClickListener();
		
		photo=(ImageView) findViewById(R.id.photo);
		photo.setOnClickListener(clickListener);
		
		String photoPath=MyApplication.getInstance().getLocalPhoto();
		if (photoPath!=null && !"".equals(photoPath)) {
			bitmap=ImageHelper.getBitmapFromPath(BaseFragmentActivity.this, photoPath);
		}
		if (bitmap!=null) {
			photo.setImageBitmap(ImageHelper.getRoundBitmap(bitmap));
		}
		
		officeBtn=(LinearLayout) findViewById(R.id.office);
		officeBtn.setOnClickListener(clickListener);
		
		knowledgeBtn=(LinearLayout) findViewById(R.id.medical_knowledge);
		knowledgeBtn.setOnClickListener(clickListener);
		
		consultingBtn=(LinearLayout) findViewById(R.id.consulting);
		consultingBtn.setOnClickListener(clickListener);
		
		homeDocBtn=(LinearLayout) findViewById(R.id.home_doctor);
		homeDocBtn.setOnClickListener(clickListener);
		
		fragContainer=(LinearLayout) findViewById(R.id.frag_container);
	
		ActionBarMenuClick actionBarMenuClick=new ActionBarMenuClick();
		
		searchText=(TextView) findViewById(R.id.search_text);
		
		menuControlBtn=(FrameLayout) findViewById(R.id.menuControlBtn);
		menuControlBtn.setOnClickListener(actionBarMenuClick);
		
		webSiteBtn = (FrameLayout) findViewById(R.id.webSiteBtn);
		webSiteBtn.setOnClickListener(actionBarMenuClick);
		
		searchBtn=(FrameLayout) findViewById(R.id.searchBtn);
		searchBtn.setOnClickListener(actionBarMenuClick);
		
		articleBtn=(FrameLayout) findViewById(R.id.articleBtn);
		knowledgeCountTip=(TextView) findViewById(R.id.knowledgeCountTip);
		articleBtn.setOnClickListener(actionBarMenuClick);
		
		videoBtn=(FrameLayout) findViewById(R.id.videoBtn);
		videoCountTip=(TextView) findViewById(R.id.videoCountTip);
		videoBtn.setOnClickListener(actionBarMenuClick);
		
		handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if (msg.what == MSG_VERIFY) {
					String[] verifyInfoArray = (String[]) msg.obj;
					String verifyInfo = verifyInfoArray[0];
					if (!ConstConfig.ACCOUNT_VALID.equals(verifyInfo)) {
						//验证出错或已过有效期则弹出窗口告知用户
						LoadingTip.hideDialog();
						AlertDialog.Builder builder = new AlertDialog.Builder(BaseFragmentActivity.this);
				    	builder.setIcon(R.drawable.alert_icon);
				    	builder.setTitle("提示");
				    	builder.setCancelable(false);
				    	if ("账号未激活请先注册！".equals(verifyInfo)) {
				    		builder.setMessage("帐号未激活，点击确定前往医师谷网站进行注册！\n如需帮助请联系医师宝客服中心 18702537275 18702613050");
				    		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface arg0, int arg1) {
									// TODO Auto-generated method stub
									Intent intent = new Intent();        
							        intent.setAction(Intent.ACTION_VIEW);  
							        Uri content_url = Uri.parse(URLConfig.WEBSITE + "reg.php");   
							        intent.setData(content_url);            
							        startActivity(intent);
								}
							});
				    		builder.setNegativeButton("取消", null);
						} else {
							builder.setMessage(verifyInfo);
					    	builder.setPositiveButton("确定", null);
						}
				    	builder.create().show();
					} else {
						if (!NetUtil.hasNetwork(BaseFragmentActivity.this)) {
							LoadingTip.hideDialog();
							LoadingTip.showToast(BaseFragmentActivity.this, "请连接网络！");
							return;
						}
						//在有效期内则开始下载数据
						switch (updateWhich) {
						case MSG_ARTICLE:
							DbOperator.getInstance(BaseFragmentActivity.this).updateDirs(handler, MSG_DIR);
							DbOperator.getInstance(BaseFragmentActivity.this).updateHealthManager(handler, MSG_HEALTH);
							DbOperator.getInstance(BaseFragmentActivity.this).updateAllArticles(handler, MSG_ARTICLE, verifyInfoArray[1], verifyInfoArray[2]);
							break;
							
						case MSG_VIDEO:
							DbOperator.getInstance(BaseFragmentActivity.this).updateDirs(handler, MSG_DIR);
							DbOperator.getInstance(BaseFragmentActivity.this).updateAllVideos(handler, MSG_VIDEO, verifyInfoArray[1], verifyInfoArray[2]);
							break;
							
						default:
							break;
						}
					}
					return;
				}
				
				if (updateWhich==MSG_ARTICLE) {
					switch (msg.what) {
					case MSG_DIR:
						dirCount=msg.arg2;
						dirDone=true;
						if (healthDone && articleDone) {
							LoadingTip.hideDialog();
							DialogHelper.showConfirmDialog(BaseFragmentActivity.this, "健康管理本次升级完成"+"\n医学栏目本次升级"+dirCount+"条"+"\n医学知识库本次升级"+articleOrVideoCount+"条");
							updateCountTip();
						}
						break;
						
					case MSG_HEALTH:	
						healthCount=msg.arg2;
						healthDone=true;
						if (dirDone && articleDone) {
							LoadingTip.hideDialog();
							DialogHelper.showConfirmDialog(BaseFragmentActivity.this, "健康管理本次升级完成"+"\n医学栏目本次升级"+dirCount+"条"+"\n医学知识库本次升级"+articleOrVideoCount+"条");
							updateCountTip();
						}
						break;
						
					case MSG_ARTICLE:	
						articleOrVideoCount=msg.arg2;
						articleDone=true;
						if (dirDone && healthDone) {
							LoadingTip.hideDialog();
							DialogHelper.showConfirmDialog(BaseFragmentActivity.this, "健康管理本次升级完成"+"\n医学栏目本次升级"+dirCount+"条"+"\n医学知识库本次升级"+articleOrVideoCount+"条");
							updateCountTip();
						}
						break;
						
					case MSG_UPFATE_COUNT:
						LoadingTip.setDialogMessage("正在升级文字技术..." + "\n已升级：" + msg.arg1);
						break;
						
					default:
						break;
					}
				} else if (updateWhich==MSG_VIDEO) {
					switch (msg.what) {
					case MSG_DIR:
						dirCount=msg.arg2;
						dirDone=true;
						if (videoDone) {
							LoadingTip.hideDialog();
							DialogHelper.showConfirmDialog(BaseFragmentActivity.this, "医学栏目本次升级"+dirCount+"条"+"\n医学视频本次升级"+articleOrVideoCount+"条");
							updateCountTip();
						}
						break;
						
					case MSG_VIDEO:	
						articleOrVideoCount=msg.arg2;
						videoDone=true;
						if (dirDone) {
							LoadingTip.hideDialog();
							DialogHelper.showConfirmDialog(BaseFragmentActivity.this, "医学栏目本次升级"+dirCount+"条"+"\n医学视频本次升级"+articleOrVideoCount+"条");
							updateCountTip();
						}
						break;
						
					case MSG_UPFATE_COUNT:
						LoadingTip.setDialogMessage("正在升级视频技术..." + "\n已升级：" + msg.arg1);
						break;
						
					default:
						break;
					}
				}
			}
		};
	}
	
	protected final void getData(){
		updateCountTip();
	}
	
	
	/**
	 * 更新显示医学文章和视频数量
	 */
	private void updateCountTip(){
		new Thread() {
			public void run() {
				List<Integer> articleAndVideoCount=DbOperator.getInstance(BaseFragmentActivity.this).getUpdateCount();
				final int articleCount=articleAndVideoCount.get(0);
				final int videoCount=articleAndVideoCount.get(1);
				runOnUiThread(new Runnable() {
					public void run() {
						if (articleCount > 0) {
							knowledgeCountTip.setText(String.valueOf(articleCount));
							knowledgeCountTip.setVisibility(View.VISIBLE);
						} else {
							knowledgeCountTip.setText("");
							knowledgeCountTip.setVisibility(View.GONE);
						}
						
						if (videoCount > 0) {
							videoCountTip.setText(String.valueOf(videoCount));
							videoCountTip.setVisibility(View.VISIBLE);
						} else {
							videoCountTip.setText("");
							videoCountTip.setVisibility(View.GONE);
						}
					}
				});
			}
		}.start();
	}
	
	
	/**
	 * 这些是需要子类重写的方法
	 */
	protected void onHeaderClicked(){};
	protected void onOfficeClicked(){};
	protected void onMedicalKnowledgeClicked(){};
	protected void onConsultingClicked(){};
	protected void onHomeDoctorClicked(){};
	
	//主菜单按钮点击事件
    protected class MainMenuClickListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			
			case R.id.photo:  //点击头像
				Intent userInfoIntent=new Intent(BaseFragmentActivity.this,UserInfoActivity.class);
				startActivity(userInfoIntent);
				break;
			
			case R.id.office:
				onOfficeClicked();
				break;

			case R.id.medical_knowledge:
				onMedicalKnowledgeClicked();
				break;
				
			case R.id.consulting://这里是点击医疗联盟远程会诊=========================================
				onConsultingClicked();
				break;
				
			case R.id.home_doctor:
				onHomeDoctorClicked();
				break;
				
			default:
				break;
			}
		}	
	}
    

    
    //actionBar按钮点击事件
    private final class ActionBarMenuClick implements OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.menuControlBtn:  //主菜单控制按钮
				if (mainMenu.getVisibility()==View.VISIBLE) {
					mainMenu.setVisibility(View.GONE);
				} else if (mainMenu.getVisibility()==View.GONE) {
					mainMenu.setVisibility(View.VISIBLE);
					mainMenu.setVisibility(View.VISIBLE);
				}
				break;
				
			case R.id.searchBtn:
				String keyWord=search.getText().toString().trim();
				if (keyWord==null || "".equals(keyWord)) {
					Toast.makeText(BaseFragmentActivity.this, "请输入搜索内容！", Toast.LENGTH_SHORT).show();
				} else {
					searchByKeyWord(keyWord);
				}
				break;
				
			case R.id.webSiteBtn:
				if (!NetUtil.hasNetwork(BaseFragmentActivity.this)) {
					Toast.makeText(BaseFragmentActivity.this, "请连接网络！", Toast.LENGTH_SHORT).show();
					return;
				}
				Intent intent = new Intent();        
		        intent.setAction(Intent.ACTION_VIEW);    
		        Uri content_url = Uri.parse(URLConfig.WEBSITE);   
		        intent.setData(content_url);            
		        startActivity(intent);
		        break;
				
				
			case R.id.articleBtn:  //升级医学知识库按钮
				InputAndCheckAccountPwd(MSG_ARTICLE);
				break;
				
			case R.id.videoBtn:   //视频升级按钮
				InputAndCheckAccountPwd(MSG_VIDEO);
				break;
				
			default:
				break;
			}
		}   	
    }
    
    
    /**
     * 升级前弹出输入密码对话框
     * @param updateWhich 区分升级文章还是视频
     */
    private void InputAndCheckAccountPwd(final int updateWhich) {
    	if (!NetUtil.hasNetwork(BaseFragmentActivity.this)) {
			Toast.makeText(BaseFragmentActivity.this, "请连接网络！", Toast.LENGTH_SHORT).show();
			return;
		}
    	if (!hasGotoWebSite) {
			Intent intent = new Intent();        
	        intent.setAction("android.intent.action.VIEW");    
	        Uri content_url = Uri.parse(URLConfig.WEBSITE);   
	        intent.setData(content_url);            
	        startActivity(intent);
	        hasGotoWebSite = true;
	        return;
		}
    	
    	AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.common_dialog);
    	builder.setIcon(R.drawable.alert_icon);
    	builder.setTitle("数据升级验证");
    	builder.setCancelable(false);
    	View view = View.inflate(this, R.layout.verify_account_pwd_dialog, null);
    	final TextView account = (TextView) view.findViewById(R.id.account);
    	final EditText pwd = (EditText) view.findViewById(R.id.pwd);
    	
    	final UserBean user = MyApplication.getInstance().getUserBean();
    	
    	if (user != null && user.getUsername() != null) {
    		account.setText("医师宝序号：" + user.getUsername());
		} else {
			LoadingTip.showToast(BaseFragmentActivity.this, "未找到相关的用户信息！");
			return;
		}
    	
    	builder.setView(view);
    	builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
				String account_txt = (user != null && user.getUsername() != null) ? user.getUsername() : null;
				String pwd_txt = pwd.getText().toString();
				if (account_txt == null || account_txt.trim().length() <=0 || pwd_txt == null || pwd_txt.trim().length() <= 0) {
					DialogHelper.changeMshowing(dialog, false);
					LoadingTip.showToast(BaseFragmentActivity.this, "请输入密码！");
					return;
				}
				if (!NetUtil.hasNetwork(BaseFragmentActivity.this)) {
					LoadingTip.showToast(BaseFragmentActivity.this, "请连接网络！");
					return;
				}
				
				//验证帐号
				setOriginalValue();
				BaseFragmentActivity.this.updateWhich = updateWhich;
				
				if (user != null) {
					if (account_txt.equals(user.getUsername()) && pwd_txt.equals(user.getMm()) && FileHelper.getImieStatus(BaseFragmentActivity.this).equals(user.getSerial_number())) {
						DbOperator.getInstance(BaseFragmentActivity.this).verifyUserDate(handler, MSG_VERIFY, account_txt, pwd_txt);
						switch (updateWhich) {
						case MSG_ARTICLE:
							LoadingTip.showDialog(BaseFragmentActivity.this, "正在升级文字技术...");
							break;
							
						case MSG_VIDEO:
							LoadingTip.showDialog(BaseFragmentActivity.this, "正在升级视频技术...");
							break;
							
						default:
							break;
						}
					} else {
						LoadingTip.showToast(BaseFragmentActivity.this, "请输入正确的密码！");
						pwd.setText("");  //清除错误的密码
						DialogHelper.changeMshowing(dialog, false);  //对话框不消失
						return;
					}
					
				} else {
					LoadingTip.showToast(BaseFragmentActivity.this, "sorry，没有相关的用户信息！");
				}
				DialogHelper.changeMshowing(dialog, true);
			}
		});
    	builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
				DialogHelper.changeMshowing(dialog, true);
			}
		});
    	dialog = builder.create();
    	dialog.show();
    }
    
    
    //设置子菜单
    protected void initiaSubMenu(){
    	subMenu=(GridView) findViewById(R.id.subMenu);
    }
    
    /**
     * 回复升级前的初始值
     */
    private void setOriginalValue(){
    	dirCount=healthCount=articleOrVideoCount=INITIA_VALUE;
    	updateWhich=0;
    	dirDone=healthDone=articleDone=videoDone=false;
    }
	
	
	//搜索方法
	protected void searchByKeyWord(String keyWord){
		
	}
	
	
	/**
	 * 通知用户有新的数据可升级
	 */
	protected void noticeNewData() {
		if (!NetUtil.hasNetwork(this) || MyApplication.getInstance().getHasNoticeNewData())
			return;
		
		RequestParams params = new RequestParams(URLConfig.MAX_ID_URL, this, null, ArticleVideoMaxIdListBean.class);
		GetDataThread.getInstance(this).getDataFromServer(ConstConfig.GET, params, new GetDataThread.DataCallback<ArticleVideoMaxIdListBean>() {
			@Override
			public void processData(final ArticleVideoMaxIdListBean paramObject, boolean paramBoolean) {
				// TODO Auto-generated method stub
				if (paramObject != null && paramObject.getBean(0) != null) {
					new AsyncTask<String, Integer, Integer>() {
						protected Integer doInBackground(String[] arg0) {
							ArticleVideoMaxIdBean bean = paramObject.getBean(0);
							Integer articleMaxId = bean.getArticle_max_id();
							Integer videoMaxId = bean.getVideo_max_id();
							boolean hasNewArticle = false, hasNewVideo = false;  //是否有新的医学文章、视频
							if (articleMaxId != null && articleMaxId > 0) {
								int articleLocalMaxId = DbOperator.getInstance(BaseFragmentActivity.this).getArticleMaxId();
								if (articleMaxId.intValue() > articleLocalMaxId)
									hasNewArticle = true;
							}
							if (videoMaxId != null && videoMaxId > 0) {
								int videoLocalMaxId = DbOperator.getInstance(BaseFragmentActivity.this).getVideoMaxId();
								if (videoMaxId.intValue() > videoLocalMaxId)
									hasNewVideo = true;
							}
							Integer messageResId = null;
							if (hasNewArticle && !hasNewVideo)
								messageResId = R.drawable.notice_update_article;
							else if (!hasNewArticle && hasNewVideo)
								messageResId = R.drawable.notice_update_video;
							else if (hasNewArticle && hasNewVideo)
								messageResId = R.drawable.notice_update_article_video;
							
							return messageResId;
						}
						
						protected void onPostExecute(Integer messageResId) {
							if (messageResId != null) {
								View view = View.inflate(BaseFragmentActivity.this, R.layout.prompt_update_article_dialog_layout, null);
								ImageView ivMessage = (ImageView) view.findViewById(R.id.iv_pic);
								ivMessage.setImageResource(messageResId);
								
								AlertDialog.Builder builder = new AlertDialog.Builder(BaseFragmentActivity.this, R.style.common_dialog);
								builder.setTitle(getString(R.string.prompt));
								builder.setIcon(R.drawable.alert_icon);
								builder.setView(view);
								builder.setNegativeButton(getString(R.string.confirm), null);
								builder.setCancelable(true);
								builder.create().show();
							}
							/**
							if (messageResId != null) {
								View view = View.inflate(BaseFragmentActivity.this, R.layout.prompt_update_article_dialog_layout, null);
								TextView tvMessage = (TextView) view.findViewById(R.id.tv_message);
								tvMessage.setText(getString(messageResId));
								int size = (int) tvMessage.getTextSize();
								switch (messageResId.intValue()) {
								case R.string.has_new_article_data_tip:
									Bitmap b1 = BitmapFactory.decodeResource(getResources(), R.drawable.article_icon);
									b1 = Bitmap.createScaledBitmap(b1, size, size, false);
									ImageSpan isp1 = new ImageSpan(BaseFragmentActivity.this, b1);
									SpannableString sbs1 = new SpannableString("icon");
									sbs1.setSpan(isp1, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
									tvMessage.append(sbs1);
									break;
									
								case R.string.has_new_video_data_tip:
									Bitmap b2 = BitmapFactory.decodeResource(getResources(), R.drawable.video_icon2);
									b2 = Bitmap.createScaledBitmap(b2, (int) (1.5f * size), size, false);
									ImageSpan isp2 = new ImageSpan(BaseFragmentActivity.this, b2);
									SpannableString sbs2 = new SpannableString("icon");
									sbs2.setSpan(isp2, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
									tvMessage.append(sbs2);
									break;
									
								case R.string.has_new_article_video_data_tip:
									Bitmap b3 = BitmapFactory.decodeResource(getResources(), R.drawable.article_icon);
									b3 = Bitmap.createScaledBitmap(b3, size, size, false);
									ImageSpan isp3 = new ImageSpan(BaseFragmentActivity.this, b3);
									SpannableString sbs3 = new SpannableString("icon");
									sbs3.setSpan(isp3, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
									tvMessage.append(sbs3);
									
									tvMessage.append(getString(R.string.and));
									
									Bitmap b4 = BitmapFactory.decodeResource(getResources(), R.drawable.video_icon2);
									b4 = Bitmap.createScaledBitmap(b4, (int) (1.5f * size), size, false);
									ImageSpan isp4 = new ImageSpan(BaseFragmentActivity.this, b4);
									SpannableString sbs4 = new SpannableString("icon");
									sbs4.setSpan(isp4, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
									tvMessage.append(sbs4);
									break;	

								default:
									break;
								}
								tvMessage.append(getString(R.string.update_new_tech));
								AlertDialog.Builder builder = new AlertDialog.Builder(BaseFragmentActivity.this, R.style.common_dialog);
								builder.setTitle(getString(R.string.prompt));
								builder.setIcon(R.drawable.alert_icon);
								builder.setView(view);
								builder.setNegativeButton(getString(R.string.confirm), null);
								builder.setCancelable(true);
								builder.create().show();
							}
							*/
						}
					}.execute("");
				}
				
				MyApplication.getInstance().setHasNoticeNewData(true);
			}
		});
	}
	
	
    
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		if (handler != null) {
			//退出页面时移除消息队列防止内存泄露
			handler.removeCallbacksAndMessages(null);
		}
		super.onDestroy();
	}
}
